﻿using KinonekoSoftware.Foundation.IO;
using KinonekoSoftware.JuXiaoYouDB.Core;

namespace KinonekoSoftware.Studio.Internals
{
    public sealed class RepositoryManager : IRepositoryManager
    {
        private string _dir;
        
        public RepositoryManager()
        {
            var ai              = Ioc.Get<ApplicationInformation>();
            var settingFileName = Path.Combine(ai.SettingFolder, Platform.FileName_JuXiaoYou5_Repo);

            if (string.IsNullOrEmpty(settingFileName))
            {
                Directory = null;
            }
            else
            {
                Directory = File.ReadAllText(settingFileName);
            }
        }

        public string CheckDir(string directory) => FolderHelper.CheckDir(directory);
        
        public bool IsExists { get; private set; }

        public string Directory
        {
            get => _dir;
            set
            {
                _dir     = value;
                IsExists = !string.IsNullOrEmpty(value);
            }
        }
    }
}